Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Pass prop from top level of react project from file using render from "react-dom"

I'm currently working on a personal project just to get a bit better using react.

I use react-router for navigation. My index.js file has the following

import { render } from "react-dom";
import App from "./App";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import TukTukTours from "./components/TukTukTours";
import BycicleTours from "./components/BicycleTours";
import WalkingTours from "./components/WalkingTours";

const rootElement = document.getElementById("root");
render(
  <BrowserRouter>
     <Routes>
        <Route path="/" element={<App />} />
        <Route path='tuktuktours' element={<TukTukTours/>}/>
        <Route path='bycicletours' element={<BycicleTours/>}/>
        <Route path='walkingtours' element={<WalkingTours/>}/>
    </Routes>
  </BrowserRouter>,
  rootElement
);

The App component is what loads the main page basically, I have a nav bar there which has a select box that changes between two languages. Once the user changes all the text in the page changes from one language to another. I want the same to happen on my three other pages (Routes above).

For that I want to pass down a state variable to App, WalkingTours, BycicleTours and TukTukTours to dynamically change the content of the pages.

The way I have index.js structured it doesn't look like I can use useState hook to achieve what I want. Something similar to the below;

import { render } from "react-dom";
import App from "./App";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import TukTukTours from "./components/TukTukTours";
import BycicleTours from "./components/BicycleTours";
import WalkingTours from "./components/WalkingTours";
import { useState } from "react";

const [language, setLanguage] = useState("GB");

const changeLanguage = (language) => setLang(language);
const rootElement = document.getElementById("root");
render(
  <BrowserRouter>
     <Routes>
        <Route path="/" element={<App language={language} setLang={changeLanguage} />} />
        <Route path='tuktuktours' element={<TukTukTours language={language}/>}/>
        <Route path='bycicletours' element={<BycicleTours language={language}/>}/>
        <Route path='walkingtours' element={<WalkingTours language={language}/>}/>
    </Routes>
  </BrowserRouter>,
  rootElement
);

I know the above is not valid because I can't use hooks outside react function components or custom hook functions.

What would be the best way to achieve what I have above?

Many thanks

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!